﻿
@{
    Layout = null;
}

<!DOCTYPE html>

<html>
<head>
    <meta name="viewport" content="width=device-width" />
    <title>新增轮播图</title>
    <link href="~/Areas/Back/lib/layui/css/layui.css" rel="stylesheet" />
    <script src="~/Areas/Back/lib/layui/layui.js"></script>
</head>
<body>
    <div class="layui-container" style="margin-top:50px;margin-bottom:150px">
        @*设计师名字*@
        <form class="layui-form" id="addFrom" onsubmit="return false">
            <div class="layui-form-item">
                <label class="layui-form-label">名字</label>
                <div class="layui-input-block">
                    <input type="text" id="Name" class="layui-input" placeholder="请输入名字" />
                </div>
            </div>
            @*职位*@
                <div class="layui-form-item">
                    <label class="layui-form-label">职位</label>
                    <div class="layui-input-block">
                        <input type="text" id="Position" class="layui-input" placeholder="请输入职位" />
                    </div>
                </div>
                @*封面*@
                <div class="layui-form-item">
                    <label class="layui-form-label">上传图片</label>
                    <div class="layui-input-block">
                        <input type="file" id="uplaodImg" name="uplaodImg" />
                        <input type="hidden" id="ImgUrl" />
                    </div>
                </div>
                @*填充图片的位置*@
                <div class="layui-form-item">
                    <div class="layui-input-block">
                        <img id="imgPhoto" class="layui-upload-img" style="width:180px; height:140px" />
                    </div>
                </div>
                @*提交和重置按钮*@
                <div class="layui-form-item">
                    <div class="layui-input-block">
                        <button class="layui-btn" lay-submit lay-filter="subAdd">立即提交</button>
                        <button type="reset" class="layui-btn layui-btn-primary">重置</button>
                    </div>
                </div>


            </form>
    </div>
</body>
<script>
    layui.use(['form', 'layedit','upload'], function () {
       var  form = layui.form;
       var layedit = layui.layedit;
       var upload = layui.upload;
       var $ = layui.$;
       var layer = layui.layer;
        //图片上传
       upload.render({
           elem: "#uplaodImg",
           url: "/Back/Designer/Uploadphoto",
           done: function (res) {
               //上传成功
               if (res.success == true) {
                   $("#ImgUrl").val(res.path);
                   $("#imgPhoto").attr("src", "/" + res.path);
                   layer.msg("上传成功");
               } else {
                   layer.msg("上传失败:" + res.message);
               }
           }
       });
       form.on('submit(subAdd)', function () {
           $.ajax({
               url: "AddDel",
               method: "post",
               dataType: "json",
               data: {
                   Name: $("#Name").val(),
                   Position: $("#Position").val(),
                   ImgUrl: $("#ImgUrl").val(),
               },
               success: function (res) {
                   if (res.success == true) {
                       layer.msg(res.msg);
                       //关闭当前窗口，并且刷新列表
                       var index = parent.layer.getFrameIndex(window.name);
                       //关闭弹窗
                       parent.layer.close(index);
                       //刷新父页面
                       parent.location.reload();
                   } else {
                       layer.msg(res.msg);
                   }
               }
           })
       })

    })
</script>
</html>
